package com.devmindset.jpatoolbox.onetomany;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.devmindset.jpatoolbox.ReadOnlyModelList;
import com.devmindset.jpatoolbox.base.BaseEntity;


/**
 * Entity on the inverse side used in the 1-to-M wiring tests.
 *
 * @author <a href="mailto:ice.penov@devmindset.com">Ice Penov</a>
 */
@Entity(name = "INVERSE_1M")
@Table(name = "INVERSE_1M")
public class Inverse extends BaseEntity {
  
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "inverse")
  private List<Forward> forwards = new ArrayList<Forward>();

  @SuppressWarnings("unchecked")
  public List<Forward> getForwards() {
    return ReadOnlyModelList.decorate(this.forwards);
  }

  public void setForwards(List<Forward> forwards) {
    com.devmindset.jpatoolbox.OneToManyUtil.wireCollection(this, forwards, Inverse.class, Forward.class);
  }
 
  public void addForward(Forward forward) {
    com.devmindset.jpatoolbox.OneToManyUtil.wireAddition(this, forward, Inverse.class, Forward.class);
  }
  
  /**
   * Remove a forward from this inverse.
   * 
   * @param forward the forward
   */
  public void removeForward(Forward forward) {
    com.devmindset.jpatoolbox.OneToManyUtil.wireRemoval(this, forward, Inverse.class, Forward.class);
  }
  
}
